package com.datounet.flutterapp.methodChannel;

import android.content.Intent;

import com.datounet.flutterapp.MyApplication;
import com.datounet.flutterapp.WakeUpHelper;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

/**
 * @author 41784
 */
public class OnMethodCallDelegate {

    void dispatch(MethodCall call, MethodChannel.Result result) {
        switch (call.method) {
            //处理来自Dart的方法调用
            case MethodTypes.INVOKE_DEMO:
                result.success("MethodChannelPlugin收到：" + call.arguments);
                //返回结果给Dart
                break;
            case MethodTypes.LIGHT_ON:
                WakeUpHelper.wakeLockGet();
                WakeUpHelper.popForeground(MyApplication.getInstance());
                WakeUpHelper.openLock(MyApplication.getInstance());
                break;
            case MethodTypes.OPEN_PKG:
                try {
                    Intent intent = MyApplication.getInstance().getPackageManager().getLaunchIntentForPackage(call.arguments.toString());
                    MyApplication.getInstance().startActivity(intent);
                    result.success(1);
                } catch (Exception e) {
                    result.error("","","");
                    e.printStackTrace();
                }
                break;
            default:
                result.notImplemented();
        }
    }
}



